home *** CD-ROM | disk | FTP | other *** search
- /*
- * $
- * $ FILE : scrollbox.c
- * $ VERSION : 1
- * $ REVISION : 48
- * $ DATE : 08-Dec-93 14:59
- * $
- * $ Author : mvk
- * $
- *
- * This is an example for gbscrollbox.library
- *
- * It creates a scrollbox with five items, if you click into a item
- * it is delete. If you size the window the all items are displayed
- * again.
- *
- */
- /*
- Related Files: gbscrollbox.doc, gbscrollbox.h <- Our Scrollbox gadget
- egsintui.doc, egsintui.h <- window stuff
- egsgadbox.doc, egsgadbox.h <- The actual gadbox
- main.c
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <exec/types.h>
- #include <dos/dos.h>
- #include <exec/memory.h>
- #include <proto/dos.h>
- #include <proto/exec.h>
- #include <egs/egs.h>
- #include <egs/egsintui.h>
- #include <egs/egsgadbox.h>
- #include <egs/egb/gbscrollbox.h>
- #include <egs/proto/all.h>
-
- /*
- ** Protos
- */
- EI_WindowPtr CreateScrollWindow (EI_WindowPtr win);
- APTR My_FindGadget(EB_GadContext GadCon,WORD ID);
- void My_AddItems(EB_GadContext GadCon,EI_WindowPtr win);
- void Clean_Exit (void);
-
- struct Library *EGSIntuiBase=NULL; // EGSIntuition
- struct Library *EGBScrollBase=NULL; // ScrollBox
- struct Library *EGBBase=NULL; // gadbox
-
- EB_GadContext GadCon;
- EI_WindowPtr window;
- struct Node item1,item2,item3,item4,item5;
-
- void main (void) {
- EI_EIntuiMsgPtr msg;
- int class;
- struct EI_Gadget *iaddress;
-
- if (!(EGSIntuiBase = OpenLibrary ("egsintui.library",0))) {
- printf ("Unable open egsintui.library.\n");
- Clean_Exit ();
- }
- if (!(EGBScrollBase = OpenLibrary ("egb/gbscrollbox.library",0))) {
- printf ("Unable open gbmenuselect.library.\n");
- Clean_Exit ();
- }
- if (!(EGBBase = OpenLibrary ("egsgadbox.library",0))) {
- printf ("Unable open egsgadbox.library.\n");
- Clean_Exit ();
- }
-
- if (!(window = CreateScrollWindow (NULL))) {
- printf ("Unable to open Window.\n");
- Clean_Exit ();
- }
-
- for (;;) { // Forever
-
- Wait (1<<window->UserPort->mp_SigBit); // wait for our signals
-
- while ( (msg=(struct EI_EIntuiMsg *) GetMsg (window->UserPort)) != NULL) {
-
- class = msg->Class;
- iaddress = (struct EI_Gadget *)msg->IAddress;
-
- switch (class) {
-
- case EI_iCLOSEWINDOW:
- ReplyMsg ( (struct Message *)msg);
- Clean_Exit ();
- break;
- // User has begun to resize window
- case EI_iSIZEVERIFY:
- EI_LockIntuition ();
- EI_RemoveGList (window,GadCon->First, GadCon->Num);
- EB_DeleteGadContext (GadCon);
- EI_UnlockIntuition ();
- ReplyMsg ( (struct Message *)msg);
- break;
-
- case EI_iNEWSIZE:
-
- EI_LockIntuition ();
- window = CreateScrollWindow (window);
- EI_AddGList ( window,GadCon->First,GadCon->Num );
- My_AddItems( GadCon,window ); // Add Items
- EI_UnlockIntuition ();
-
- ReplyMsg ( (struct Message *)msg);
- break;
- // User has pressed a scroll gadget
- case EI_iGADGETDOWN:
-
- printf ("ItemsName = %s\n",
- ((EGB_ScrollGadPtr)iaddress)->ActText->ln_Name);
-
- EI_LockIntuition ();
- EGB_RemItemFromScrollBox(window,iaddress, // Delete
- ((EGB_ScrollGadPtr)iaddress)->ActText);
-
- EI_UnlockIntuition ();
-
- ReplyMsg ( (struct Message *)msg);
- break;
- }
- }
- }
- }
-
- /*
- **
- ** CreateScrollGadgets
- **
- */
- EI_WindowPtr CreateScrollWindow (EI_WindowPtr win)
- {
-
- EB_GadBoxPtr root;
-
- GadCon = EB_CreateGadContext (NULL,NULL,-1,-1);
-
- root = EB_CreateHorizBox (GadCon);
- EB_AddLastSon (root,EB_CreateHorizFill (GadCon,EB_FILL_ALL,0));
- EB_AddLastSon (root,EGB_CreateLateScrollBox (GadCon,10,20,10,40,0,0x100));
- EB_AddLastSon (root,EB_CreateHorizFill (GadCon,EB_FILL_ALL,0));
-
- root = EB_CreateMasterWindow (GadCon,win,root);
-
- if (EB_ProcessGadBoxes (GadCon,root))
- {
-
- if (win==NULL) {
- GadCon->NewWin->IDCMPFlags |= EI_iCLOSEWINDOW |
- EI_iSIZEVERIFY |
- EI_iNEWSIZE |
- EI_iGADGETUP |
- EI_iGADGETDOWN;
-
- GadCon->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE)|(EI_WINDOWSIZE);
-
- GadCon->NewWin->Flags |= EI_SIZEBBOTTOM;
-
- win=EI_OpenWindow (GadCon->NewWin);
-
- My_AddItems(GadCon,win);
-
- }
- return (win);
-
- }else
- return NULL;
- }
-
- /*
- **
- ** Make Items
- **
- */
- void My_AddItems(EB_GadContext GadCon,EI_WindowPtr win)
- {
- EI_GadgetPtr gad;
- /*
- ** Find Scrollbox Gadget
- */
- gad=My_FindGadget(GadCon,0x100);
-
- if(gad)
- {
-
- /*
- ** if ln_Pri = 1then item is on the top of the list
- ** and highlight.
- */
-
- item1.ln_Pri=0;
- item2.ln_Pri=0;
- item3.ln_Pri=1; // First
- item4.ln_Pri=0;
- item5.ln_Pri=0;
-
- /*
- ** Itemnames
- */
-
- item1.ln_Name= "One";
- item2.ln_Name= "Two";
- item3.ln_Name= "Three";
- item4.ln_Name= "Four";
- item5.ln_Name= "Five";
-
- /*
- ** Add Items to Scollbox
- */
- EGB_AddItemToScrollBox(win,gad,&item1);
- EGB_AddItemToScrollBox(win,gad,&item2);
- EGB_AddItemToScrollBox(win,gad,&item3);
- EGB_AddItemToScrollBox(win,gad,&item4);
- EGB_AddItemToScrollBox(win,gad,&item5);
- EGB_ActivateElem(win,gad,&item1);
- EGB_UpdateScrollBox(window,gad); // Is used to add items, if
- // a window is already opened
-
- }
- }
-
- /*
- **
- ** This function searched for Subgadget in a MasterGadget,
- ** because all Gadgets are in a MasterWindow.
- **
- */
- APTR My_FindGadget(EB_GadContext GadCon,WORD ID)
- {
- /*
- ** MasterGadPtr because the window is create with
- ** EB_CreateMasterWindow function
- */
- return( EB_FindGadget(
- ((EI_MasterGadPtr)GadCon->First)->FirstSon,
- ((EI_MasterGadPtr)GadCon->First)->NumSons,ID));
- }
-
- void Clean_Exit (void) {
-
- if (window)
- EI_CloseWindow (window);
- if (GadCon)
- EB_DeleteGadContext (GadCon);
- if (EGBBase)
- CloseLibrary (EGBBase);
- if (EGBScrollBase)
- CloseLibrary (EGBScrollBase);
- if (EGSIntuiBase)
- CloseLibrary (EGSIntuiBase);
-
- exit (0);
- }
-